package com.cqupt.exception;

import com.cqupt.model.vo.Result;
import com.cqupt.model.vo.ResultCodeEnum;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
    }

    @ExceptionHandler(BusinessException.class)
    public Result error(BusinessException e) {
        e.printStackTrace();
        return Result.build(null, e.getResultCodeEnum());
    }

//    @ExceptionHandler(IllegalStateException.class)
//    public Result error(IllegalStateException e) {
//        e.printStackTrace();
//        return Result.build(null, ResultCodeEnum.PARAM_ERROR);
//    }

}
